<template>
  <div class="valueset">
    <div class="outmain ba_f">
      <div class="shuju_title mar_b20">
        <div class="shuju_title_text">
          <span>储值设置</span>
        </div>
      </div>
      <el-form ref="form" :model="form" label-width="180px">
        <el-form-item label="储值功能">
          <el-radio-group v-model="form.open">
            <el-radio label="1">开启</el-radio>
            <el-radio label="2">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="自定义充值金额">
          <el-radio-group v-model="form.moneyOpen">
            <el-radio label="1">开启</el-radio>
            <el-radio label="2">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="最低充值金额" v-if="form.moneyOpen=='1'">
          <el-input v-model="form.downMoney" placeholder="请输入最低充值金额"></el-input>
        </el-form-item>
        <el-form-item label="储值说明">
          <baidu-ueditor :content="form.details" @ueditor="getUeditor"></baidu-ueditor>
        </el-form-item>
      </el-form>
    </div>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>
<script>
import { getConfig, postConfig } from '@/api/setup';
import baiduUeditor from '@/plugins/baidu-ueditor';
export default {
  components: { baiduUeditor },
  created() {
    this.bus.$emit('loading', true);
    this.init();
  },
  data() {
    return {
      form: {
        open: '1',
        moneyOpen: '1',
        downMoney: '',
        details: ''
      }
    };
  },
  methods: {
    getUeditor(content) {
      this.form.details = content;
    },
    async init() {
      const { data } = await getConfig({ ident: 'recharge' });
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
      this.bus.$emit('loading', false);
    },
    submitForm() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form.ident = 'recharge';
          this.form.identName = '充值配置';
          const { msg } = await postConfig(this.form);
          this.$baseMessage(msg, 'success');
          this.init();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
